package com.xr.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xr.sunnyday.constant.MessageConstant;
import com.xr.sunnyday.entity.PageResult;
import com.xr.sunnyday.entity.QueryPageBean;
import com.xr.sunnyday.entity.Result;
import com.xr.sunnyday.pojo.CheckItem;
import com.xr.sunnyday.service.CheckitemService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/Checkitem")
public class CheckitemController {
    @Reference
    private CheckitemService checkitemService;


    @RequestMapping("/findAll")
    public Result findAll() {

        List<CheckItem> list = checkitemService.findAll();
        if (list != null && list.size() > 0) {
            return new Result(true, "查询成功", list);
        }
        return new Result(false, "查询失败");
    }

    @PostMapping("/findpage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        PageResult page = checkitemService.findPage(queryPageBean);
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, page);
    }

    @RequestMapping("/add")
    public Result add(@RequestBody CheckItem checkItem) {
        checkitemService.add(checkItem);
        return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
    }

    @PostMapping("/deleteById")
    public Result deleteById(int id) {
        System.out.println("删除方法前端控制qi");
        checkitemService.deleteById(id);
        return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }

    @GetMapping("/findById")
    public Result findById(int id){
        CheckItem checkItem = checkitemService.findById(id);
        return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem);
    }

    @PostMapping("/update")
    public Result update(@RequestBody CheckItem checkItem){
        checkitemService.update(checkItem);
        return new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }

}
